Dino Geek, try to help you

How to change permalinks in WordPress with `.htaccess`?


To change permalinks in WordPress using `.htaccess`, you’ll need to update the rewrite rules appropriately. The `.htaccess` file is an Apache web server configuration file that contains directives to control the server’s behavior. By modifying it, you can change how WordPress handles URL structures for your website.

Here’s a step-by-step guide on how to do this:

1. Backup Your Site and `.htaccess` File: Always backup your website and the existing `.htaccess` file before making any changes to avoid data loss.

1. Access Your `.htaccess` File: You can usually find this file in the root directory of your WordPress installation. You can access it through an FTP client like FileZilla or via the file management tool provided by your web hosting service.

1. Edit the `.htaccess` File: Open the `.htaccess` file using a text editor. WordPress generates a default set of rewrite rules when you change the permalink structure through the WordPress dashboard (`Settings` > `Permalinks`). Below is an example of the default WordPress `.htaccess` content:

\`\`\`apache # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ – [L] RewriteCond %{REQUEST\_FILENAME} !-f RewriteCond %{REQUEST\_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress \`\`\`

1. Add Custom Rewrite Rules: If you wish to add custom permalink structures, you’ll need to adjust rules or add new ones. Here are some common scenarios:

- Changing from Default to Post Name Permalinks: \`\`\`apache # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index.php$ – [L] RewriteCond %{REQUEST\_FILENAME} !-f RewriteCond %{REQUEST\_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress \`\`\`

- Adding Custom Post Type Rewrite Rules: If you have a custom post type, you might need to add specific rules: \`\`\`apache RewriteRule ^custom-post-type/([a-zA-Z0-9_-]+)/?$ index.php?custom_post\_type=$1 [L] \`\`\`

1. Save and Upload the `.htaccess` File: After editing, save the file and upload it back to the server if you are using an FTP client.

1. Check Permalinks in WordPress Admin: Go to your WordPress admin dashboard, navigate to `Settings` > `Permalinks`, and save the settings. This step is essential as it will rebuild the permalink structure.

1. Testing: Visit your website to ensure that the new permalink structure works correctly. Check various pages and post types to confirm that all URLs resolve as expected.

  1. Examples

- Default to Pretty Permalinks: If you initially had the default URL structure (`?p=123`) and you want to change it to a “pretty” permalink (e.g., `/post-name/`), the `.htaccess` file will need the standard WordPress rewrite rules mentioned above.

- Custom Category Base: If you want to change the category base from `category` to `topics`: \`\`\`apache RewriteRule ^topics/([^/]+)/?$ /index.php?category\_name=$1 [L] \`\`\`

  1. Sources

- WordPress Codex: The official WordPress documentation provides extensive details on `.htaccess` and permalink structures. (https://wordpress.org/support/article/htaccess/)

- Apache Documentation: For more advanced `.htaccess` rules, consult the Apache HTTP Server documentation. (https://httpd.apache.org/docs/current/howto/htaccess.html)

By correctly implementing these changes, you can effectively customize your WordPress site’s permalinks as required.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use